﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WorldBankBBS.Logic;
using WorldBankBBS.Menus;

namespace WorldBankBBS.EMail
{
    public class EmailMenuProvider : IMenuProvider
    {
        public EmailMenuProvider()
        {
            MenuItems = new List<MenuItem>(
                new[]
                {
                    new MenuItem
                    {
                        Abbreviation = "N",
                        Full = "NEW",
                        ResourcePattern = "WorldBankBBS.EMail:WorldBankBBS.EMail.EMailPathHandler:CreateEMail",
                        TakesParameters = false,
                        UseCurrentContext = false,
                    },
                    new MenuItem
                    {
                        Abbreviation = "#",
                        Full = "READ",
                        ResourcePattern = "WorldBankBBS.EMail:WorldBankBBS.EMail.EMailPathHandler:ReadEMail|{0}",
                        TakesParameters = true,
                        UseCurrentContext = false,
                    },
                    new MenuItem
                    {
                        Abbreviation = "DC",
                        Full = "DELETE CURRENT",
                        ResourcePattern = "WorldBankBBS.EMail:WorldBankBBS.EMail.EMailPathHandler:DeleteEMail|{0}",
                        TakesParameters = false,
                        UseCurrentContext = true,
                    },
                    new MenuItem
                    {
                        Abbreviation = "D",
                        Full = "DELETE ",
                        ResourcePattern = "WorldBankBBS.EMail:WorldBankBBS.EMail.EMailPathHandler:DeleteEMail|{0}",
                        TakesParameters = true,
                        UseCurrentContext = false,
                    },
                    new MenuItem
                    {
                        Abbreviation = "RC",
                        Full = "REPLY CURRENT",
                        ResourcePattern = "WorldBankBBS.EMail:WorldBankBBS.EMail.EMailPathHandler:CreateEMail|{0}",
                        TakesParameters = false,
                        UseCurrentContext = true,
                    },
                    new MenuItem
                    {
                        Abbreviation = "R",
                        Full = "REPLY ",
                        ResourcePattern = "WorldBankBBS.EMail:WorldBankBBS.EMail.EMailPathHandler:CreateEMail|{0}",
                        TakesParameters = true,
                        UseCurrentContext = false,
                    },
                    new MenuItem
                    {
                        Abbreviation = "L",
                        Full = "LIST",
                        ResourcePattern = "WorldBankBBS.EMail:WorldBankBBS.EMail.EMailPathHandler:ListEMails",
                        TakesParameters = false,
                        UseCurrentContext = false,
                    },
                    new MenuItem
                    {
                        Abbreviation = "Q",
                        Full = "QUIT",
                        ResourcePattern = "",
                        TakesParameters = false,
                        UseCurrentContext = false,
                    },
                }
                );

            Prompt = EMailStrings.EMAIL_PROMPT;

            ShortHelpFilename = "email_help_short";
            LongHelpFilename = "email_help_long";

            GenericHelpText = EMailStrings.EMAIL_GENERIC_HELP;

        }

        public IList<MenuItem> MenuItems { get; private set; }
        public string ShortHelpFilename { get; private set; }
        public string LongHelpFilename { get; private set; }
        public string GenericHelpText { get; private set; }
        public string Prompt { get; private set; }

        public void Refresh(Session session)
        {
            var items = EMailHandler.ListEmails(session, false);
            var lookups = new Dictionary<string, Guid>();
            var count = 1;
            foreach (var l in items)
            {
                lookups.Add((count++).ToString(), l.PrivateMailUID);
            }

            session["MenuLookups"] = lookups;
        }
    }
}
